package gov.nist.ssd.swqb.commands;

import gov.nist.ssd.swqb.core.Display;
import gov.nist.ssd.swqb.core.exceptions.OutOfBoundsException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Benjamin Herbomez 
 */
public class PreviousPage implements Command {

    private Display display;

    public PreviousPage(Display d) {
        this.display = d;
    }

    @Override
    public void exec() {
        int i = display.getCurrentPageIndex();
        if (i > 0) {
            try {
                display.setPageIndex(i - 1);
            } catch (OutOfBoundsException ex) {
                Logger.getLogger(NextPage.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    @Override
    public void unExec() {

        int i = display.getCurrentPageIndex();
        try {
            display.setPageIndex(i + 1);
        } catch (OutOfBoundsException ex) {
            Logger.getLogger(NextPage.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
